package com.mtnz.njk.Service;

import com.github.pagehelper.PageHelper;
import com.mtnz.njk.Mapper.InquiryManagerMapper;
import com.mtnz.njk.Mapper.InquiryMapper;
import com.mtnz.njk.entity.InquiryEntity;
import com.mtnz.njk.result.PageInfo;
import com.mtnz.njk.result.ResponseMessage;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InquiryManagerService {
    @Autowired
    InquiryMapper inquiryMapper;


    @Autowired
    InquiryManagerMapper inquiryManagerMapper;

    /**
     * 咨询客服列表
     *
     * @param inquiryStatus
     * @param key
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    public ResponseResult listInquiry(Integer inquiryStatus, String key, Integer pageNum, Integer pageSize) throws Exception {
        PageHelper.startPage(pageNum,pageSize);
        List<InquiryEntity> listInquiry = inquiryManagerMapper.getListInquiry(inquiryStatus, key);
        PageInfo<InquiryEntity> inquiryEntityPageInfo = new PageInfo<>(listInquiry);
        return new ResponseResult(ResponseMessage.OK,inquiryEntityPageInfo);
    }

    /**
     * 处理咨询请求
     *
     * @param inquiryStatus
     * @param inquiryId
     * @return
     * @throws Exception
     */
    public ResponseResult dealInquiry(Integer inquiryStatus,Integer inquiryId) throws Exception {
        InquiryEntity inquiryEntity = new InquiryEntity();
        inquiryEntity.setInquiryId(inquiryId);
        inquiryEntity.setInquiryStatus(inquiryStatus);
        int i = inquiryMapper.updateByPrimaryKeySelective(inquiryEntity);
        if(i > 0)
            return new ResponseResult(ResponseMessage.OK);
        return new ResponseResult(ResponseMessage.FAIL);
    }
}
